package com.util;

import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.api.dom.java.InnerEnum;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.api.dom.xml.XmlElement;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Set;

public class Mycommit implements CommentGenerator {
	    private Properties properties;
	    private Properties systemPro;
	    private boolean suppressDate;
	    private boolean suppressAllComments;
	    private String currentDateStr;
	    public Mycommit() {
	        super();
	        properties = new Properties();
	        systemPro = System.getProperties();
	        suppressDate = false;
	        suppressAllComments = false;
	        currentDateStr = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
	    }

	@Override
	public void addConfigurationProperties(Properties properties) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn)
	{
		  if (suppressAllComments) {
	            return;
	        }
	        StringBuilder sb = new StringBuilder();
	        field.addJavaDocLine("/**");
	        sb.append(" * ");
	        sb.append(introspectedColumn.getRemarks());
	        field.addJavaDocLine(sb.toString().replace("\n", " "));
	        field.addJavaDocLine(" */");
   }

	@Override
	public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		 if (suppressAllComments) {
	            return;
	        }
	        StringBuilder sb = new StringBuilder();
	        field.addJavaDocLine("/**");
	        sb.append(" * ");
	        sb.append(introspectedTable.getFullyQualifiedTable());
	        field.addJavaDocLine(sb.toString().replace("\n", " "));
	        field.addJavaDocLine(" */");
		
	}

	@Override
	public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		 if (suppressAllComments) {
		        return;
		    }

		    StringBuilder sb = new StringBuilder();

		    innerClass.addJavaDocLine("/**");
		    sb.append(" * ");
		    sb.append(introspectedTable.getFullyQualifiedTable());
		    innerClass.addJavaDocLine(sb.toString());

		    sb.setLength(0);
		    sb.append(" * @author ");
		    sb.append(systemPro.getProperty("user.name"));
		    sb.append(" ");
		    sb.append(currentDateStr);

		    //      addJavadocTag(innerClass, markAsDoNotDelete);

		    innerClass.addJavaDocLine(" */");
		
	}

	@Override
	public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addGetterComment(Method method, IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
		// TODO Auto-generated method stub
		if (suppressAllComments) {
	        return;
	    }

	    method.addJavaDocLine("/**");

	    StringBuilder sb = new StringBuilder();
	    sb.append(" * ");
	    sb.append(introspectedColumn.getRemarks());
	    method.addJavaDocLine(sb.toString());

	    sb.setLength(0);
	    sb.append(" * @return ");
	    sb.append(introspectedColumn.getActualColumnName());
	    sb.append(" ");
	    sb.append(introspectedColumn.getRemarks());
	    method.addJavaDocLine(sb.toString());

	    //      addJavadocTag(method, false);

	    method.addJavaDocLine(" */");
		
	}

	@Override
	public void addSetterComment(Method method, IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
		// TODO Auto-generated method stub
		  if (suppressAllComments) {
		        return;
		    }


		    method.addJavaDocLine("/**");
		    StringBuilder sb = new StringBuilder();
		    sb.append(" * ");
		    sb.append(introspectedColumn.getRemarks());
		    method.addJavaDocLine(sb.toString());

		    Parameter parm = method.getParameters().get(0);
		    sb.setLength(0);
		    sb.append(" * @param ");
		    sb.append(parm.getName());
		    sb.append(" ");
		    sb.append(introspectedColumn.getRemarks());
		    method.addJavaDocLine(sb.toString());

		    //      addJavadocTag(method, false);

		    method.addJavaDocLine(" */");
		
	}

	@Override
	public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addJavaFileComment(CompilationUnit compilationUnit) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addComment(XmlElement xmlElement) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addRootComment(XmlElement rootElement) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
                                           Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
                                           IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
                                   Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
                                   IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable,
                                   Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}

}
